May I know how can I setup a mail client other than gmail, in the documentation it says to use smtpServer package but I can't seem to figure it out. I'm using Webmail and want to know how I can set it up.
sendMail() async {
String username = 'test#gmail.com';
String password = '*******';
final smtpServer = gmail(username, password);
final message = Message()
..from = Address(username)
..recipients.add(_email) //User Email
One of the steps is to turn on less secure apps on your Google Account:
check this link https://support.google.com/accounts/answer/6010255?hl=en#zippy=
Related
I need to setup email sending from shared mailbox using EWS/Exchange.asmx in custom application and don't have idea how to pass username and password.
Outlook 356
Shared mailbox: shared#outlook.com
User address: user#outlook.com (with license and full access to
shared... I can log into shared using web client)
Parameters to enter in the app are:
Host / URL -> https://outlook.office365.com/EWS/Exchange.asmx
Domain -> domainname
Username -> ?????
Password -> domain password for user#outlook.com
How to fill username to log into shared using user password? I've tried some combinations like: user#outlook.com\shared etc. but it is not working (unauthorized error). When I enter just user's name and pass email is sent correctly, but I need message to be sent from shared mailbox address.
Any ideas?
Use "user#outlook.com\shared#outlook.com" as the username. You can use POP3 or IMAP. Here is an examaple which uses OpenPop package:
private string hostname = "pop-mail.outlook.com";
private int port = 995;
private bool useSsl = true;
private string username = "user#outlook.com\\shared#outlook.com";
private string password = "YourPassword";
public List<Message> FetchAllMessages()
{
// The client disconnects from the server when being disposed
using(Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(hostname, port, useSsl);
// Authenticate ourselves towards the server
client.Authenticate(username, password);
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
// We want to download all messages
List<Message> allMessages = new List<Message>(messageCount);
I set up a website using web2py and I'm looking for help to setup an email notification that will email the the person when they get a private message.
I already have the system able to have a semi message system/private message and I'm wondering how do I integrate that all together so that if a person gets a message, the system can automatically email that user. I been looking around to how to set it up but no luck for myself.
Thank you.
Edit: Before I start trying to integrate the messaging system, I wanted to test it out with the registration since that's the only thing I could find about web2py and email notification.
Edit2: Got the register to work and it says "email is sent". However, no actual email is sent.
This is all in the Models, menu.py. Also tried putting this in the controller, default.py.
auth.settings.register_next = URL('Welcome')
def Welcome():
User_Email = auth.user.email
mail.send(User_Email,'Welcome To website','Welcome To website')
if request.vars.lan == 'En':
redirect('index',vars={'lan':'En'})
else:
redirect('index')
#from gluon.tools import Mail
#mail = Mail()
#mail.settings. = True
#mail = auth.settings.mailer
mail = auth.settings.mailer
mail.settings.tls = False
mail.settings.server = "tls://smtp.gmail.com:587"
mail.settings.sender = "...#gmail.com"
mail.settings.login = "...#gmail.com:password"
# sends an verification e-mail upon registration
auth.settings.registration_requires_verification = True
def send_email(user, subject):
message = "" "Multi line string for %(first_name)s......"
message = open("somefile.html", "r").read()
# you also have the option to include everyone in bcc=[...]
mail.send(to=user.email,
subject=subject,
message=message % user)
user = db(db.auth_user).select()
for user in user:
send_email(user, "some subject")
Also have in the controller/default.py
def login():
auth.settings.registration_requires_verification = True
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
I don't seem to get it. I can create some code to send an email like this:
String userName = "user#domain.com";
String password = "your password";
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("ToAddress"));
msg.From = new MailAddress(userName);
msg.Subject = "Test Office 365 Account";
msg.Body = "Testing email using Office 365 account.";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.office365.com";
client.Credentials = new System.Net.NetworkCredential(userName, password);
client.Port = 587;
client.EnableSsl = true;
client.Send(msg);
Or I can create an app in our Azure AD and set the permissions and send an email with the GRAPH API right?
Is there any possible reason I would want to use the GRAPH API to do this ?
Well you're asking for an opinion, so it's hard to give an all-inclusive answer. However, one reason that you might prefer Graph over SMTP is that it uses OAuth, so you do not need to ask for or store the user's username or password.
I am beginner in java and I want to send an email in java, for that I am using this code in Java. But my code is throwing an exception, and I need a heads-up why…
This is stack trace of exception:
javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbsNX
534-5.7.14 No6jJbDc4l7fZ_WLdBD0sNHIIp_nLvplRMm0bYFBnZBF_XOyVvNSdd1FenDZJPwBTFQyRH
534-5.7.14 lriPK3myMm-dXkW3zK0-6XpO7BzI8hfRcByG1k7YiVzXlddTvs7QhjtgCWNcrzMBuPhoof
534-5.7.14 GjME2TgYzXJVHz5MV98nRnr_kq-kP7RmgOtX3IQHLwM5E8QGBC9-2THVQr_Ch_U0-1nZsc
534-5.7.14 yoPuNEw> Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 wr6sm26888533wjc.24 - gsmtp
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:892)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:814)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:728)
at javax.mail.Service.connect(Service.java:364)
at javax.mail.Service.connect(Service.java:245)
at SendEmail.sendFromGMail(SendEmail.java:50)
at SendEmail.main(SendEmail.java:18)
sent
This is my code
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendEmail {
private static String USER_NAME = "me";
private static String PASSWORD = "xyz";
private static String RECIPIENT = "abc#seecs.edu.pk";
public static void main(String[] args) {
String from = USER_NAME;
String pass = PASSWORD;
String[] to = { RECIPIENT };
String subject = "Java send mail example";
String body = "Welcome to JavaMail!";
sendFromGMail(from, pass, to, subject, body);
System.out.println("sent");
}
private static void sendFromGMail(String from, String pass, String[] to, String subject, String body) {
Properties props = System.getProperties();
String host = "smtp.gmail.com";
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
for( int i = 0; i < to.length; i++ ) {
toAddress[i] = new InternetAddress(to[i]);
}
for( int i = 0; i < toAddress.length; i++) {
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
message.setSubject(subject);
message.setText(body);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
catch (AddressException ae) {
ae.printStackTrace();
}
catch (MessagingException me) {
me.printStackTrace();
}
}
}
I had the same problem! Google prevents access for less secure apps.
This is how I solved it:
Log in from your browser to that email account.
Go to https://www.google.com/settings/security/lesssecureapps
You will see Turn off or Turn on. Click on Turn on, then try your code again. It should work now.
Make sure Less secure apps is TURNED ON
https://www.google.com/settings/security/lesssecureapps
Allow each app to send email
Go to https://accounts.google.com/b/0/DisplayUnlockCaptcha
and click on Continue.
This time: you can use your app to send email and all operations are allowed.
More links:
https://support.google.com/accounts/answer/6010255
https://productforums.google.com/forum/#!topic/gmail/9KCgzXY4G_c
allow less secure apps from your google account settings
https://www.google.com/settings/security/lesssecureapps
open your gmail> goto settings > IMAP/POP settings > enable IMAP
goto this url and turn this on (completing all these steps will surely work)
https://www.google.com/accounts/DisplayUnlockCaptcha
official guide for help
https://support.google.com/mail/answer/7126229?hl=en-GB&visit_id=637246238859828954-474780158&rd=2
I am also facing same problem.
Google does't give you direct open port access.
If you are using your your google account for mail sending please Turn on the setting by clicking on this link.
google go here : https://www.google.com/settings/security/lesssecureapps
Best of luck hope it will work for you as well.
Its not just about enabling the "less secure apps" from google admin page.
The above fix did not solve the issue for me. I contacted google and they asked me to add couple of TXT records to my DNS list. You will need a DKIM key that you will need to generate from the G Suite admin settings for gmail.
We are sending mails from our local system.
We got our IPs white listed.
We have a scenario where we have to send email on behalf of somebody.
for ex: our email id is: support#mycompany.com
but we need to send email with a from address: john#abc.com
When we send with different from address, the receiving mail client displays "phishing" error.
One of the solution is to use "via" as dispayed in google link
https://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=185812
We also want the message to be displayed like this in receivers inbox.
Any pointers in this will help us a lot.
thanks in advance.
Note: We are using localhost as the smtp.
Read about email headers. you can add email headers while creating the mail message at runtime.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.jcom.net");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
for further reading check this :
http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274
http://javamail.kenai.com/nonav/javadocs/javax/mail/internet/package-summary.html
#http://javamail.kenai.com/nonav/javadocs/javax/mail/internet/MimeMessage.html
You can create aliases for the smtp server too.