wie zum senden von E-Mails über outlook von java
ich habe mit den folgenden code für das senden von mail innerhalb einer Domäne.
public void sendMail(String mailServer, String from, String to,
String subject, String messageBody, String[] attachments)
throws MessagingException, AddressException {
//Setup mail server
Properties props = System.getProperties();
props.put("mail.smtp.host", mailServer);
//Get a mail session
Session session = Session.getDefaultInstance(props, null);
//Define a new mail message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
//Create a message part to represent the body text
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(messageBody);
//use a MimeMultipart as we need to handle the file attachments
Multipart multipart = new MimeMultipart();
//add the message body to the mime message
multipart.addBodyPart(messageBodyPart);
//add any file attachments to the message
addAtachments(attachments, multipart);
//Put all message parts in the message
message.setContent(multipart);
//Send the message
Transport.send(message);
System.err.println("Message Send");
}
protected void addAtachments(String[] attachments, Multipart multipart)
throws MessagingException, AddressException {
for (int i = 0; i < attachments.length ; i++) {
String filename = attachments[i];
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
//use a JAF FileDataSource as it does MIME type detection
DataSource source = new FileDataSource(filename);
attachmentBodyPart.setDataHandler(new DataHandler(source));
//assume that the filename you want to send is the same as the
//actual file name - could alter this to remove the file path
attachmentBodyPart.setFileName(filename);
//add the attachment
multipart.addBodyPart(attachmentBodyPart);
}
}
aber wenn mit dem gleichen code versuche ich eine email zu senden, die außerhalb der domain, sagen, ich bin senden von E-Mails aus [email protected] zu mhsharma@gmail,com dann schlägt es fehl und gibt mir die folgende Fehlermeldung. 550 5.7.1 Rcpt command failed: Mail denied due to site's policy
Bin ich etwas fehlt im obigen code.
Bitte helfen Sie mir
Schicken Sie es von Ihrem Arbeitsumfeld? Ich gehe davon aus, dass Sie blockiert Google Mail.
InformationsquelleAutor M.J. | 2010-10-02
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ich vermute, das ist nicht ein problem in Ihrem code, sondern in Ihrem E-mail-server (
sendmail
?) - Konfiguration. Würde ich reden, wer verwaltet Ihre E-mail-Infrastruktur.InformationsquelleAutor Brian Agnew
Ist es wahrscheinlich, dass Ihre lokalen mail-server erfordert Authentifizierung vor dem senden von E-mail hinaus in die Welt. Dies ist eine gemeinsame Politik, um zu verhindern, dass Spammer von Weiterleitung Ihrer E-mail durch.
InformationsquelleAutor Brad Mace
Vorausgesetzt, Ihr Rechner ist Outlook installiert,... haben Sie versucht, mit moyosoft java outlook connector? es ist ziemlich einfach zu bedienen und führt durch Netzwerk-Einschränkungen, weil es eine Verbindung zu Ihrem Outlook-Anwendung und sendet dann die E-mail, so dass jede Beschränkung auf smtp-ports oder Server - /proxy-Richtlinien werden ignoriert, wenn der Outlook-client funktioniert Prima.
wenn Sie es tun mit dem command-line-server-Seite, dann ich denke, diese Antwort ist nutzlos für Sie.
Quelle: ich hatte ähnliches problem (nicht gleiche Fehlercode, mehr wie eine intranet-Beschränkung), und die Nutzung dieser Bibliothek ist mein problem gelöst, weil der oben gepostet.
InformationsquelleAutor Isidro.rn